package com.lww.feature.test.cpu;

import com.sun.xml.internal.ws.runtime.config.TubelineFeatureReader;
import org.junit.Test;

import javax.sound.midi.Soundbank;
import java.math.BigDecimal;
import java.util.Scanner;

/**
 * User: yian
 * Date: 2018/7/6
 */
public class test {

    /**
     * 死循环CPU 100% ，由于本机是多核的所以其他程序也不是很卡
     */
    @Test
    public void ss() {
        while (true) {

        }
    }

    public static void main(String[] args) {
        Integer a = 1000000;
        Integer b = 1000000;
        Thread threadA = new Thread(new RunnableA(a, b));
        Thread threadB = new Thread(new RunnableB(a, b));
        threadA.start();
        threadB.start();
        try {
            Thread.sleep(50000000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    @Test
    public void lock() {
        Integer a = 1;
        Integer b = 1;
        Thread threadA = new Thread(new RunnableA(a, b));
        Thread threadB = new Thread(new RunnableB(a, b));
        threadA.start();
        threadB.start();
        try {
            Thread.sleep(50000000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    static class RunnableA implements Runnable {

        Integer a;
        Integer b;

        public RunnableA(Integer a, Integer b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public void run() {
            synchronized (b) {
                try {
                    System.out.println("AAAAAAAAAStart");

                    Thread.sleep(8000);

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                synchronized (a) {
                    System.out.println("AAAAAAAAAEND");
                }
            }

        }
    }

    static class RunnableB implements Runnable {
        Integer a;
        Integer b;

        public RunnableB(Integer a, Integer b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public void run() {
            synchronized (a) {

                try {
                    System.out.println("BBBBBBBBBBBBBBBSTART");

                    Thread.sleep(10000);

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                synchronized (b) {
                    System.out.println("BBBBBBBBBBBBBBBEND");
                }
            }


        }
    }

    @Test
    public void sss() {
        Integer integer = new Integer(2);
        Integer integer2 = new Integer(integer);
        System.out.println(integer==integer2);
        BigDecimal bigDecimal = new BigDecimal(0.1);
        BigDecimal bigDecima2 = new BigDecimal("0.1");
        System.out.println(bigDecima2.equals(bigDecimal));
        System.out.println(bigDecimal);
        System.out.println(bigDecima2);
    }


}
